#include <iostream>
#include <string>
// #include <ostream>

using namespace std;

class Node;

#ifndef COMPONENT_H
#define COMPONENT_H

class Component
{
public:
    enum class Type
    {
        R,
        C,
        L,
        VS,
        CS
    };

    Component(string name, Type type, double value, bool isShorted=false, bool isOpen=false)
    {
        this->name = name;
        this->type = type;
        this->value = 0;
        this->node1 = NULL;
        this->node2 = NULL;
        this->value = value;
        this->isShorted = isShorted;
        this->isOpen = isOpen;
    }

    string get_type()
    {
        return typeToString(type);
    }

    string get_name()
    {
        return name;
    }

    double get_value()
    {
        return value;
    }

    Node *get_node1()
    {
        return node1;
    }

    Node *get_node2()
    {
        return node2;
    }

    void set_nodes(Node *node1, Node *node2)
    {
        this->node1 = node1;
        this->node2 = node2;
    }

    bool is_shorted()
    {
        return isShorted;
    }

    void set_shorted(bool isShorted)
    {
        this->isShorted = isShorted;
    }

    void set_open(bool isOpen)
    {
        this->isOpen = isOpen;
    }
    
    bool is_open()
    {
        return isOpen;
    }

    void print()
    {
        cout << name << "\t" << value << endl;
    }

private:
    string name;
    Type type;
    double value;
    Node *node1;
    Node *node2;
    bool isShorted;
    bool isOpen;

    string typeToString(Type type) const {
        switch (type) {
            case Type::R:
                return "Resistor";
            case Type::C:
                return "Capacitor";
            case Type::L:
                return "Inductor";
            case Type::VS:
                return "Voltage Source";
            case Type::CS:
                return "Current Source";
            default:
                return "Unknown";
        }
    }
};

#endif